package com.yyq.thread;

/**
 * @author yyq
 * @create 2021-08-03 9:57
 */
public class syn implements java.lang.Runnable {

    static private int ticket=100;
    public static Object object=new Object();
    @Override
    public void run() {
        int i=0;

        while (true) {
            i++;
            show();


        }
    }

    private synchronized void show(){
        if(ticket > 0){

            System.out.println(Thread.currentThread().getName() + "票号" + ticket );
            ticket--;
        }
    }



}

class buyticket1{
    public static void main(String[] args) {
        syn one=new syn();

        Thread one_th=new Thread(one);
        Thread two_th=new Thread(one);
        one_th.setName("售票窗口一");
        two_th.setName("售票窗口二");
        one_th.start();
        two_th.start();
    }
}
